import { createSlice } from "@reduxjs/toolkit";
import store from "store2";

const tabulationSlice = createSlice({
  name: "Tabulation",
  initialState: {
    tabulation: [],
    axiosCondition: {
      current: store.get("tabulationCurrent") || 1, //当前页码number  √
      pagesize: store.get("tabulationPagesize") || 4, //每页显示的条数number √
      search: null, //搜索的关键字string
      filter: null, //折扣筛选hot,sale
      saleType: null, //折扣类型number(5 ~ 10)
      sortType: null, //排序类型id || sale || price
      sortMethod: null, //排序方式ASC || DESC
      category: null, //分类筛选条件string
    },
  },
  reducers: {
    setTabulation(state, action) {
      state.tabulation = action.payload;

      // store.set("collapsed", action.payload);
    },
    setAxiosCondition(state, action) {
      state.axiosCondition = { ...state.axiosCondition, ...action.payload };
      // console.log("setAxiosCondition", state.axiosCondition);
      store.set("tabulationCurrent", state.axiosCondition.current);
      // store.set("tabulationPagesize", state.axiosCondition.pagesize);
    },
  },
});
export const { setTabulation, setAxiosCondition } = tabulationSlice.actions;
export default tabulationSlice.reducer;
